package cn.xuyang520.tyim.sys.controller;

import cn.xuyang520.tyim.sys.domain.TySysRelationGroupAuthorityRepository;
import cn.xuyang520.tyim.sys.service.TySysAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by admin on 2017/4/4.
 */
@SuppressWarnings("all")
@Controller
@RequestMapping("/tySysAuthorityController")
public class TySysAuthorityController extends TySysBaseController {

    @Autowired
    private TySysAuthorityService tySysAuthorityService;
	@Autowired
    private TySysRelationGroupAuthorityRepository tySysRelationGroupAuthorityRepository;
    @Autowired
    private JdbcTemplate jdbcTemplate ;

    @RequestMapping("/authoritySet")
    public String authoritySet(String groupId, Model model) {
        model.addAttribute("codes", tySysAuthorityService.findAuthorityCodesByGroupCode(groupId));
        model.addAttribute("groupCode", groupId);
        return "page/sys/authoritySet";
    }



    @RequestMapping("/addAuthority")
    @ResponseBody
    public Object addAuthority(String groupCode, String authCode) {
        tySysAuthorityService.setAuthorityCodeByGroupCode(groupCode, authCode, true);
        return success();
    }
    @RequestMapping("/delAuthority")
    @ResponseBody
    public Object delAuthority(String groupCode, String authCode) {
        tySysAuthorityService.setAuthorityCodeByGroupCode(groupCode, authCode, false);
        return success();
    }


}
